package com.example.smartcitydemo.ui.smartbus.fragment

import android.os.Bundle
import androidx.fragment.app.activityViewModels
import androidx.navigation.fragment.findNavController

import com.example.smartcitydemo.R
import com.example.smartcitydemo.base.BaseFragment
import com.example.smartcitydemo.bean.BusStationData
import com.example.smartcitydemo.databinding.FragmentSmartBusFirstBinding
import com.example.smartcitydemo.ui.smartbus.adapter.SmartBusFirstAdapter
import com.example.smartcitydemo.viewModel.smartBus.SmartBusViewModel

/**
 * @PACKAGE_NAME:
 * @NAME: Caleb.F
 * @DATE: 2021/8/25 8:36
 * @Email: 1919796283@qq.com
 */
class SmartBusFirstFragment :
    BaseFragment<FragmentSmartBusFirstBinding>(R.layout.fragment_smart_bus_first) {
    private val smartBusViewModel: SmartBusViewModel by activityViewModels()

    private val smartBusAdapter: SmartBusFirstAdapter by lazy {
        SmartBusFirstAdapter()
    }

    override fun addObservers(myViewBinding: FragmentSmartBusFirstBinding) {
        smartBusViewModel.choiceItemData.observe(viewLifecycleOwner) {
            myViewBinding.data = it
            myViewBinding.rvSmartBusStation.apply {
                smartBusAdapter.setDiffNewData(it.childData.toMutableList())
            }
        }
    }


    override fun initView(
        myViewBinding: FragmentSmartBusFirstBinding,
        savedInstanceState: Bundle?
    ) {
        myViewBinding.apply {
            typeBarSmartBusInfoSecond.typeBarText.text = "线路站点信息"
            toolbarSmartBusFirst.tvContent.text = "路线信息"
            rvSmartBusStation.run {
                adapter = smartBusAdapter
                smartBusAdapter.apply {
                    setEmptyView(R.layout.loading_layout)
                    setDiffCallback(BusStationData.DiffCallBack)
                }
            }
            bottomSmartBusFirst.btnSmartBusPrevious.setOnClickListener {
              this@SmartBusFirstFragment.findNavController().navigateUp()
            }
            bottomSmartBusFirst.btnSmartBusNext.setOnClickListener {
                this@SmartBusFirstFragment.findNavController().navigate(R.id.action_navigation_smart_bus_first_to_navigation_smart_bus_second)
            }

        }
    }

    override fun initData() {

    }
}